<template>
  <el-container class="mainContent">
    <el-row>
      <el-col class="title">家庭医生签约统计图</el-col>
    </el-row>
    <el-row class="content">
      <el-col class="contentLeft" :span="18">
        <el-row class="leftTop"></el-row>
        <el-row class="leftBottom"></el-row>
      </el-col>
      <el-col class="contentRight" :span="6" >
        <el-row>
          <el-col class="subtitle">各签约团队签约数量排名</el-col>
        </el-row>
        <el-row class="evrow" v-for="(item,index) in qianNum" :key="index">
          <el-col :span="8">
            <span class="num">{{index +1}}</span>
          </el-col>
          <el-col :span="8" >
            <span class="text">{{item.contractTeam}}</span>
          </el-col>
          <el-col :span="8"><span class="total">{{item.contractNumber}}</span></el-col>
        </el-row>
      </el-col>
    </el-row>
  </el-container>
</template>
<script>
export default {
  name: "StatisticalChart",
  data() {
    return {
      mon: {},
      monNum: [],
      personNum: [],
      qianNum:[]
    };
  },
  methods: {
    formatter(row, column) {
      return row.address;
    },
    //获取每月的签约数量
    getMonNum() {
      this.axios({
        methods: "get",
        url: "/getMonNum",
      })
        .then((res) => {
          console.log(res);
          if (res.data.code === 200) {
            this.mon = res.data.data;
            for (let i in this.mon) {
              // this.monNum[i]=this.mon[i]
              this.monNum.push(this.mon[i]);
            }
            this.drawNum();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //获取居民统计数量
    getPersonNum() {
      this.axios({
        url: "/getPersonNum",
        methods: "get",
      })
        .then((res) => {
          console.log(res);
          if (res.data.code === 200) {
            this.personNum = res.data.data;
          }
          this.drawType();
          // console.log(this.personNum)
        })
        .catch((err) => {
          console.log(err);
        });
    },
    drawNum() {
      var myChart = this.$echarts.init(
        document.getElementsByClassName("leftTop")[0]
      );

      myChart.setOption({
        title: {
          text: "居民签约数量趋势",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        xAxis: {
          type: "category",
          data: [
            "1月",
            "2月",
            "3月",
            "4月",
            "5月",
            "6月",
            "7月",
            "8月",
            "9月",
            "10月",
            "11月",
            "12月",
          ],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: this.monNum,
            type: "bar",
          },
        ],
      });
      myChart.resize();
    },
    drawType() {
      var myChart = this.$echarts.init(
        document.getElementsByClassName("leftBottom")[0]
      );

      myChart.setOption({
        title: {
          text: "居民类型统计",
          textStyle: {
            color: "#333",
          },
          left: "center",
        },
        grid: {
          left: 0,
          top: 0,
          right: 0,
          bottom: 0,
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          left: "100",
          top: "center",
          itemHeight: "20",
          orient: "vertical",
        },
        series: [
          {
            type: "pie",
            radius: [30, 170],
            center: ["50%", "50%"],
            roseType: "radius",
            itemStyle: {
              borderRadius: 8,
            },
            data: this.personNum,
          },
        ],
      });
      myChart.resize();
    },
    //获取前十的
    getQian(){
      this.axios({
        url:"/getQianYueNum",
        method:"get"
      })
      .then(res=>{
        console.log(res)
        if(res.data.code===200){
          this.qianNum=res.data.data
        }
      })
      .catch(err=>{
        console.log(err)
      })
    }
  },
  created() {},
  mounted() {
    //  window.addEventListener("resize",this.getMonNum)
    //window.addEventListener("resize",this.getPersonNum)

    this.$nextTick(() => {
      this.getMonNum();
      this.getPersonNum();
      this.getQian()
    });
  },
};
</script>
<style lang="less">
.mainContent {
  width: 100%;
  flex-direction: column;
  text-align: left;
}
.title {
  margin-bottom: 30px;
  font-size: 20px;
  font-weight: 600;
}
.subtitle{
  margin-bottom: 30px;
  color: #333;
  font-size: 17px;
  font-weight:bold;
}
.content {
  width: 100%;
  height: 500px;
}
.contentLeft,
.contentRight {
  height: 1000px;
  text-align: center;
}
.leftTop,
.leftBottom {
  width: 1100px;
  height: 475px;
  // margin-bottom: 20px;
  // background-color: rgb(252, 211, 211);
}
// .leftTop>div,
// .leftBottom>div{
//   width: 100%  !important
// }
// .leftTop>div>canvas,
// .leftBottom>div>canvas{
//   width: 100%  !important;
// }
.leftBottom {
  margin-top: 50px;
}
.contentRight{
  text-align: center;
}
.contentRight span{
  height: 30px;
  line-height: 30px;
  display: inline-block;
}
.contentRight .num{
 width: 30px;
  color: white;
  border-radius: 15px;
  background: #9a60b4;
}
.evrow{
  border-left: 1px solid #a8a8a8;
  height: 90px;
  line-height: 90px;
}
</style>